package nl.weeaboo.sh.editor.area;

import java.awt.Image;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.ListSelectionModel;

import nl.weeaboo.sh.model.AreaModel;
import nl.weeaboo.sh.model.RoomModel;
import timon.common.components.IconListCellRenderer;

@SuppressWarnings("serial")
public class RoomBrowser extends JList {

	public RoomBrowser() {
		setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		setCellRenderer(new IconListCellRenderer() {
			public Image getImageFor(Object object) {
				return null;
			}
			public String getLabelFor(Object object) {
				if (object instanceof RoomModel) {
					RoomModel room = (RoomModel)object;
					return room.getId();
				}
				return "null";
			}
		});		
	}
	
	//Functions
	
	//Getters
	public RoomModel getSelectedValue() { return (RoomModel)super.getSelectedValue(); }
	
	//Setters
	public void setArea(AreaModel area) {
		DefaultListModel listModel = new DefaultListModel();
		for (RoomModel room : area.getRooms()) {
			listModel.addElement(room);
		}
		setModel(listModel);				
	}
	
}
